#include "light.h"
#include "RenderResource.h"

void DecoLight::GetPosition (FLOAT * pos) const
{
	pos[0] = (FLOAT)m_position.x;
	pos[1] = (FLOAT)m_position.y;
	pos[2] = (FLOAT)m_position.z;
	if (m_type == LT_DirectionLight)
		pos[3] = 0.f;
	else
		pos[3] = 1.f;
}
void DecoLight::GetSpecular(FLOAT* specular) const
{
	vector4 specularColor = m_specular.ToVec4();
	specular[0] = (FLOAT)specularColor.x;
	specular[1] = (FLOAT)specularColor.y;
	specular[2] = (FLOAT)specularColor.z;
	specular[3] = (FLOAT)specularColor.w;
}
void DecoLight::GetDiffuse(FLOAT* diffuse) const
{
	vector4 diffuseColor = m_diffuse.ToVec4();
	diffuse[0] = (FLOAT)diffuseColor.x;
	diffuse[1] = (FLOAT)diffuseColor.y;
	diffuse[2] = (FLOAT)diffuseColor.z;
	diffuse[3] = (FLOAT)diffuseColor.w;
}

BOOL DecoLight::IsInRange(const vector3& point) const
{
	return TRUE;
}

void DecoLight::GetSpotDirection(FLOAT* dir) const
{
	dir[0] = (FLOAT)m_spotDirection.x;
	dir[1] = (FLOAT)m_spotDirection.y;
	dir[2] = (FLOAT)m_spotDirection.z;
}

vector3 DecoLight::GetPosition() const
{
	return vector3(m_position[0], m_position[1], m_position[2]);
}
vector3 DecoLight::GetSpecular() const
{
	return m_specular.ToVec3();
}
vector3 DecoLight::GetDiffuse() const
{
	return m_diffuse.ToVec3();
}




DecoArchive& operator<< (DecoArchive& Ar, const DecoLight& light)
{
	Ar << light.m_position << light.m_specular << light.m_diffuse << (INT)light.m_type << light.m_spotCutAngle << light.m_spotDirection;
	for (INT i = 0; i < AT_Max; i++)
	{
		Ar << light.m_attenutionFactor[i];
	}
	return Ar;
}
DecoArchive& operator>> (DecoArchive& Ar, DecoLight& light)
{
	Ar >> light.m_position >> light.m_specular >> light.m_diffuse >> (INT&)light.m_type >> light.m_spotCutAngle >> light.m_spotDirection;
	for (INT i = 0; i < AT_Max; i++)
	{
		Ar >> light.m_attenutionFactor[i];
	}
	return Ar;
}
